import requests
from modules.executors import thread_pool_executor as tp
from modules.executors import process_pool_executor as pp
from modules.base import BaseModule


class Mp3Downloader(BaseModule):
    def __init__(self):
        super(Mp3Downloader, self).__init__()

    def process(self, mp3_url):
        return requests.get(mp3_url).content

    def process_single_thread(self, mp3_url_list):
        response_content_list = []
        for mp3_url in mp3_url_list:
            response_content_list.append(self.process(mp3_url))
        return response_content_list

    def process_multi_thread(self, tasks):
        response_content_list = []
        for result in tp.map(self.process, tasks):
            response_content_list.append(result)
        return response_content_list

    def process_multi_process(self, tasks):
        response_list = []
        task_list = []
        for task in tasks:
            task = pp.submit(self.process, task)
            task_list.append(task)
        for task in task_list:
            content = task.result()
            response_list.append(content)
        return response_list

    def process_coroutine(self, tasks):
        pass
